import { createRouter, createWebHashHistory } from 'vue-router'
import store from '@/store'

const routes = [
  {
		path:'/',
		name: 'home',
		redirect: '/main'
	},
  {
		path: '/main',
		name: 'main',
		component: () => import('../views/Main.vue'),
		redirect: '/main/business',
		children: [
			{
			  path: '/main/business',
			  name: 'business',
			  component: () => import('../views/BusinessView.vue')
			},
			{
			  path: '/main/food',
			  name: 'food',
			  component: () => import('../views/FoodView.vue')
			},
			{
			  path: '/main/user',
			  name: 'user',
			  component: () => import('../views/UserView.vue')
			},
			{
				path: '/main/address',
				name: 'address',
				component: () => import('../views/AddressView.vue')
			},
			{
				path: '/main/cart',
				name: 'cart',
				component: () => import('../views/CartView.vue')
			},
			{
				path: '/main/order',
				name: 'order',
				component: () => import('../views/OrderView.vue')
			}
		]
	},
	{
		path: '/login',
		name: 'login',
		component: () => import('../views/Login.vue'),
	}
]

const router = createRouter({
  history: createWebHashHistory(),
  routes
})

//路由守卫
router.beforeEach((to,from,next)=>{
	console.log('路由守卫：',to.path);
	store.state.elMenuActive = to.path;
	next(); //放行
})

export default router
